{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1d33e4c8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ad_app_pkg_name</th>\n",
       "      <th>diff_budget</th>\n",
       "      <th>last_0h</th>\n",
       "      <th>last_1h</th>\n",
       "      <th>last_2h</th>\n",
       "      <th>last_3h</th>\n",
       "      <th>last_4h</th>\n",
       "      <th>last_5h</th>\n",
       "      <th>last_6h</th>\n",
       "      <th>last_7h</th>\n",
       "      <th>...</th>\n",
       "      <th>last_16h</th>\n",
       "      <th>last_17h</th>\n",
       "      <th>last_18h</th>\n",
       "      <th>last_19h</th>\n",
       "      <th>last_20h</th>\n",
       "      <th>last_21h</th>\n",
       "      <th>last_22h</th>\n",
       "      <th>last_23h</th>\n",
       "      <th>last_24h</th>\n",
       "      <th>max_daily_budget</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>world.social.group.video.share</td>\n",
       "      <td>1200</td>\n",
       "      <td>0</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>...</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ru.yandex.yandexmaps</td>\n",
       "      <td>494</td>\n",
       "      <td>1090</td>\n",
       "      <td>1090</td>\n",
       "      <td>1090</td>\n",
       "      <td>1090</td>\n",
       "      <td>1090</td>\n",
       "      <td>1090</td>\n",
       "      <td>1090</td>\n",
       "      <td>1584</td>\n",
       "      <td>...</td>\n",
       "      <td>1584</td>\n",
       "      <td>1584</td>\n",
       "      <td>1584</td>\n",
       "      <td>1584</td>\n",
       "      <td>1584</td>\n",
       "      <td>1584</td>\n",
       "      <td>1584</td>\n",
       "      <td>1584</td>\n",
       "      <td>1584</td>\n",
       "      <td>1584</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ru.hh.android</td>\n",
       "      <td>464</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>464</td>\n",
       "      <td>464</td>\n",
       "      <td>...</td>\n",
       "      <td>464</td>\n",
       "      <td>464</td>\n",
       "      <td>464</td>\n",
       "      <td>464</td>\n",
       "      <td>464</td>\n",
       "      <td>464</td>\n",
       "      <td>464</td>\n",
       "      <td>464</td>\n",
       "      <td>464</td>\n",
       "      <td>464</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>com.plarium.raidlegends</td>\n",
       "      <td>450</td>\n",
       "      <td>550</td>\n",
       "      <td>550</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>...</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>com.WeWorld.WeCard</td>\n",
       "      <td>280</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>280</td>\n",
       "      <td>...</td>\n",
       "      <td>280</td>\n",
       "      <td>280</td>\n",
       "      <td>280</td>\n",
       "      <td>280</td>\n",
       "      <td>280</td>\n",
       "      <td>280</td>\n",
       "      <td>280</td>\n",
       "      <td>280</td>\n",
       "      <td>280</td>\n",
       "      <td>280</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 28 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  ad_app_pkg_name  diff_budget  last_0h  last_1h  last_2h  \\\n",
       "0  world.social.group.video.share         1200        0     1200     1200   \n",
       "1            ru.yandex.yandexmaps          494     1090     1090     1090   \n",
       "2                   ru.hh.android          464        0        0        0   \n",
       "3         com.plarium.raidlegends          450      550      550     1000   \n",
       "4              com.WeWorld.WeCard          280        0        0        0   \n",
       "\n",
       "   last_3h  last_4h  last_5h  last_6h  last_7h  ...  last_16h  last_17h  \\\n",
       "0     1200     1200     1200     1200     1200  ...      1200      1200   \n",
       "1     1090     1090     1090     1090     1584  ...      1584      1584   \n",
       "2        0        0        0      464      464  ...       464       464   \n",
       "3     1000     1000     1000     1000     1000  ...      1000      1000   \n",
       "4        0        0        0        0      280  ...       280       280   \n",
       "\n",
       "   last_18h  last_19h  last_20h  last_21h  last_22h  last_23h  last_24h  \\\n",
       "0      1200      1200      1200      1200      1200      1200      1200   \n",
       "1      1584      1584      1584      1584      1584      1584      1584   \n",
       "2       464       464       464       464       464       464       464   \n",
       "3      1000      1000      1000      1000      1000      1000      1000   \n",
       "4       280       280       280       280       280       280       280   \n",
       "\n",
       "   max_daily_budget  \n",
       "0              1200  \n",
       "1              1584  \n",
       "2               464  \n",
       "3              1000  \n",
       "4               280  \n",
       "\n",
       "[5 rows x 28 columns]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "# 2023年01月16日 17时47分54秒\n",
    "\n",
    "infile='/Users/msxr/develop/tmp/pandas-test/pkg_data.csv'\n",
    "\n",
    "df=pd.read_csv(infile)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "ce082818",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    28\n",
       "1    28\n",
       "2    28\n",
       "3    28\n",
       "4    28\n",
       "dtype: int64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.count(axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "0a68572c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ad_app_pkg_name    5\n",
       "diff_budget        5\n",
       "last_0h            5\n",
       "last_1h            5\n",
       "last_2h            5\n",
       "dtype: int64"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.count(axis=0).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "5f5690b4",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    30\n",
       "1    20\n",
       "2    13\n",
       "3    23\n",
       "4    18\n",
       "Name: ad_app_pkg_name, dtype: int64"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['ad_app_pkg_name'].apply(len)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "735178bb",
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "'last_1h'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[0;32m/var/folders/mj/gzzjyp5s3j5fq8jywxpy4dyc0000gn/T/ipykernel_72114/3795184168.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mlambda\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'red'\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'last_1h'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m<=\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'max_daily_budget'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0;34m''\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m/opt/anaconda3/lib/python3.9/site-packages/pandas/core/frame.py\u001b[0m in \u001b[0;36mapply\u001b[0;34m(self, func, axis, raw, result_type, args, **kwargs)\u001b[0m\n\u001b[1;32m   8738\u001b[0m             \u001b[0mkwargs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   8739\u001b[0m         )\n\u001b[0;32m-> 8740\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0mop\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   8741\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   8742\u001b[0m     def applymap(\n",
      "\u001b[0;32m/opt/anaconda3/lib/python3.9/site-packages/pandas/core/apply.py\u001b[0m in \u001b[0;36mapply\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    686\u001b[0m             \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply_raw\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    687\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 688\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply_standard\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    689\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    690\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0magg\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/opt/anaconda3/lib/python3.9/site-packages/pandas/core/apply.py\u001b[0m in \u001b[0;36mapply_standard\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    810\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    811\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0mapply_standard\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 812\u001b[0;31m         \u001b[0mresults\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mres_index\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply_series_generator\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    813\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    814\u001b[0m         \u001b[0;31m# wrap results\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/opt/anaconda3/lib/python3.9/site-packages/pandas/core/apply.py\u001b[0m in \u001b[0;36mapply_series_generator\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    826\u001b[0m             \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mv\u001b[0m \u001b[0;32min\u001b[0m \u001b[0menumerate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mseries_gen\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    827\u001b[0m                 \u001b[0;31m# ignore SettingWithCopy here in case the user mutates\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 828\u001b[0;31m                 \u001b[0mresults\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mv\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    829\u001b[0m                 \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresults\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mABCSeries\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    830\u001b[0m                     \u001b[0;31m# If we have a view on v, we need to make a copy because\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/var/folders/mj/gzzjyp5s3j5fq8jywxpy4dyc0000gn/T/ipykernel_72114/3795184168.py\u001b[0m in \u001b[0;36m<lambda>\u001b[0;34m(x)\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mlambda\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'red'\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'last_1h'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m<=\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'max_daily_budget'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0;34m''\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m/opt/anaconda3/lib/python3.9/site-packages/pandas/core/series.py\u001b[0m in \u001b[0;36m__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m    940\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    941\u001b[0m         \u001b[0;32melif\u001b[0m \u001b[0mkey_is_scalar\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 942\u001b[0;31m             \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_get_value\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    943\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    944\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mis_hashable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/opt/anaconda3/lib/python3.9/site-packages/pandas/core/series.py\u001b[0m in \u001b[0;36m_get_value\u001b[0;34m(self, label, takeable)\u001b[0m\n\u001b[1;32m   1049\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1050\u001b[0m         \u001b[0;31m# Similar to Index.get_value, but we do not fall back to positional\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1051\u001b[0;31m         \u001b[0mloc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mindex\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlabel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1052\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mindex\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_get_values_for_loc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mloc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlabel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1053\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/opt/anaconda3/lib/python3.9/site-packages/pandas/core/indexes/range.py\u001b[0m in \u001b[0;36mget_loc\u001b[0;34m(self, key, method, tolerance)\u001b[0m\n\u001b[1;32m    386\u001b[0m                 \u001b[0;32mexcept\u001b[0m \u001b[0mValueError\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0merr\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    387\u001b[0m                     \u001b[0;32mraise\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0merr\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 388\u001b[0;31m             \u001b[0;32mraise\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    389\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0msuper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmethod\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmethod\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtolerance\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtolerance\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    390\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mKeyError\u001b[0m: 'last_1h'"
     ]
    }
   ],
   "source": [
    "df.apply(lambda x: 'red' if x['last_1h']<=x['max_daily_budget'] else '')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "83ecc48e",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/var/folders/mj/gzzjyp5s3j5fq8jywxpy4dyc0000gn/T/ipykernel_72114/2056084070.py:1: FutureWarning: In a future version of pandas all arguments of DataFrame.where except for the arguments 'cond' and 'other' will be keyword-only\n",
      "  df.where((df['last_1h'] <= df['max_daily_budget']),1,-1)\n"
     ]
    },
    {
     "ename": "ValueError",
     "evalue": "For argument \"inplace\" expected type bool, received type int.",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[0;32m/var/folders/mj/gzzjyp5s3j5fq8jywxpy4dyc0000gn/T/ipykernel_72114/2056084070.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwhere\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'last_1h'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m<=\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'max_daily_budget'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m/opt/anaconda3/lib/python3.9/site-packages/pandas/util/_decorators.py\u001b[0m in \u001b[0;36mwrapper\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m    309\u001b[0m                     \u001b[0mstacklevel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mstacklevel\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    310\u001b[0m                 )\n\u001b[0;32m--> 311\u001b[0;31m             \u001b[0;32mreturn\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    312\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    313\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mwrapper\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/opt/anaconda3/lib/python3.9/site-packages/pandas/core/frame.py\u001b[0m in \u001b[0;36mwhere\u001b[0;34m(self, cond, other, inplace, axis, level, errors, try_cast)\u001b[0m\n\u001b[1;32m  10734\u001b[0m         \u001b[0mtry_cast\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mno_default\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m  10735\u001b[0m     ):\n\u001b[0;32m> 10736\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0msuper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwhere\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcond\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minplace\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlevel\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0merrors\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtry_cast\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m  10737\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m  10738\u001b[0m     @deprecate_nonkeyword_arguments(\n",
      "\u001b[0;32m/opt/anaconda3/lib/python3.9/site-packages/pandas/core/generic.py\u001b[0m in \u001b[0;36mwhere\u001b[0;34m(self, cond, other, inplace, axis, level, errors, try_cast)\u001b[0m\n\u001b[1;32m   9030\u001b[0m             )\n\u001b[1;32m   9031\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 9032\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_where\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcond\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minplace\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlevel\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0merrors\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0merrors\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   9033\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   9034\u001b[0m     \u001b[0;34m@\u001b[0m\u001b[0mfinal\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/opt/anaconda3/lib/python3.9/site-packages/pandas/core/generic.py\u001b[0m in \u001b[0;36m_where\u001b[0;34m(self, cond, other, inplace, axis, level, errors)\u001b[0m\n\u001b[1;32m   8756\u001b[0m         \u001b[0mapplied\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0ma\u001b[0m \u001b[0mfunction\u001b[0m \u001b[0meven\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcallable\u001b[0m\u001b[0;34m.\u001b[0m \u001b[0mUsed\u001b[0m \u001b[0;32min\u001b[0m \u001b[0m__setitem__\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   8757\u001b[0m         \"\"\"\n\u001b[0;32m-> 8758\u001b[0;31m         \u001b[0minplace\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mvalidate_bool_kwarg\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minplace\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"inplace\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   8759\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   8760\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0maxis\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/opt/anaconda3/lib/python3.9/site-packages/pandas/util/_validators.py\u001b[0m in \u001b[0;36mvalidate_bool_kwarg\u001b[0;34m(value, arg_name, none_allowed, int_allowed)\u001b[0m\n\u001b[1;32m    244\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    245\u001b[0m     \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mgood_value\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 246\u001b[0;31m         raise ValueError(\n\u001b[0m\u001b[1;32m    247\u001b[0m             \u001b[0;34mf'For argument \"{arg_name}\" expected type bool, received '\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    248\u001b[0m             \u001b[0;34mf\"type {type(value).__name__}.\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mValueError\u001b[0m: For argument \"inplace\" expected type bool, received type int."
     ]
    }
   ],
   "source": [
    "df.where((df['last_1h'] <= df['max_daily_budget']),1,-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "e7635bd6",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "class DateTool:\n",
    "    input_timestamp = None\n",
    "\n",
    "    def __init__(self, input_timestamp=None):\n",
    "        if input_timestamp is None:\n",
    "            self.input_timestamp = time.time()\n",
    "        elif type(input_timestamp) == int or type(input_timestamp) == float:\n",
    "            self.input_timestamp = input_timestamp\n",
    "        elif re.match(r'^\\d{8}$', input_timestamp):\n",
    "            struct_time = time.strptime(input_timestamp, '%Y%m%d')\n",
    "            self.input_timestamp = time.mktime(struct_time)\n",
    "        elif re.match(r'^\\d{10}$', input_timestamp):\n",
    "            self.input_timestamp = int(input_timestamp)\n",
    "        elif re.match(r'^\\d{4}-\\d{2}-\\d{2}$', input_timestamp):\n",
    "            struct_time = time.strptime(input_timestamp, '%Y-%m-%d')\n",
    "            self.input_timestamp = time.mktime(struct_time)\n",
    "        elif re.match(r'^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$', input_timestamp):\n",
    "            struct_time = time.strptime(input_timestamp, '%Y-%m-%d %H:%M:%S')\n",
    "            self.input_timestamp = time.mktime(struct_time)\n",
    "        else:\n",
    "            logging.error('please input right time args')\n",
    "            exit(-1)\n",
    "\n",
    "    def execution_date_producer(self, delta_hours, date_fmt):\n",
    "        \"\"\"\n",
    "        装配器\n",
    "        \"\"\"\n",
    "        input_timestamp = self.input_timestamp or time.time()\n",
    "        struct_time = datetime.datetime.fromtimestamp(input_timestamp)\n",
    "\n",
    "        if delta_hours == 0:\n",
    "            return struct_time.strftime(date_fmt)\n",
    "        else:\n",
    "            return (struct_time + datetime.timedelta(hours=delta_hours)).strftime(date_fmt)\n",
    "\n",
    "    def get_time_args(self, offset=0):\n",
    "        offset = - offset\n",
    "        time_args = {}\n",
    "        for i in range(0, 31):\n",
    "            time_args['run_date_sub_{}d'.format(i)] = self.execution_date_producer(offset - i * 24, '%Y%m%d'\n",
    "                                                                                   )\n",
    "            time_args['run_date_add_{}d'.format(i)] = self.execution_date_producer(offset + i * 24, '%Y%m%d'\n",
    "                                                                                   )\n",
    "            time_args['stat_date_sub_{}d'.format(i)] = self.execution_date_producer(offset - i * 24, '%Y-%m-%d'\n",
    "                                                                                    )\n",
    "            time_args['stat_date_add_{}d'.format(i)] = self.execution_date_producer(offset + i * 24, '%Y-%m-%d'\n",
    "                                                                                    )\n",
    "            time_args['run_year_sub_{}d'.format(i)] = self.execution_date_producer(offset - i * 24, '%Y')\n",
    "            time_args['run_year_add_{}d'.format(i)] = self.execution_date_producer(offset + i * 24, '%Y')\n",
    "            time_args['run_month_sub_{}d'.format(i)] = self.execution_date_producer(offset - i * 24, '%m')\n",
    "            time_args['run_month_add_{}d'.format(i)] = self.execution_date_producer(offset + i * 24, '%m')\n",
    "            time_args['run_day_sub_{}d'.format(i)] = self.execution_date_producer(offset - i * 24, '%d')\n",
    "            time_args['run_day_add_{}d'.format(i)] = self.execution_date_producer(offset + i * 24, '%d')\n",
    "        for i in range(0, 48):\n",
    "            time_args['run_date_sub_{}h'.format(i)] = self.execution_date_producer(offset - i, '%Y%m%d')\n",
    "            time_args['stat_date_sub_{}h'.format(i)] = self.execution_date_producer(offset - i, '%Y-%m-%d')\n",
    "            time_args['run_year_sub_{}h'.format(i)] = self.execution_date_producer(offset - i, '%Y')\n",
    "            time_args['run_month_sub_{}h'.format(i)] = self.execution_date_producer(offset - i, '%m')\n",
    "            time_args['run_day_sub_{}h'.format(i)] = self.execution_date_producer(offset - i, '%d')\n",
    "            time_args['run_hour_sub_{}h'.format(i)] = self.execution_date_producer(offset - i, '%H')\n",
    "\n",
    "            time_args['run_date_add_{}h'.format(i)] = self.execution_date_producer(offset + i, '%Y%m%d')\n",
    "            time_args['stat_date_add_{}h'.format(i)] = self.execution_date_producer(offset + i, '%Y-%m-%d')\n",
    "            time_args['run_year_add_{}h'.format(i)] = self.execution_date_producer(offset + i, '%Y')\n",
    "            time_args['run_month_add_{}h'.format(i)] = self.execution_date_producer(offset + i, '%m')\n",
    "            time_args['run_day_add_{}h'.format(i)] = self.execution_date_producer(offset + i, '%d')\n",
    "            time_args['run_hour_add_{}h'.format(i)] = self.execution_date_producer(offset + i, '%H')\n",
    "        # 默认时间\n",
    "        time_args['run_hour'] = self.execution_date_producer(offset, '%H')\n",
    "        time_args['run_date'] = self.execution_date_producer(offset, '%Y%m%d')\n",
    "        time_args['run_year'] = self.execution_date_producer(offset, '%Y')\n",
    "        time_args['run_month'] = self.execution_date_producer(offset, '%m')\n",
    "        time_args['run_day'] = self.execution_date_producer(offset, '%d')\n",
    "        time_args['stat_date'] = self.execution_date_producer(offset, '%Y-%m-%d')\n",
    "        time_args['default_airflow_date'] = self.execution_date_producer(0, '%Y%m%d')\n",
    "        return time_args\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "446e00ad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ad_app_pkg_name     world.social.group.video.share\n",
       "diff_budget                                   1200\n",
       "last_0h                                       1090\n",
       "last_1h                                       1200\n",
       "last_2h                                       1200\n",
       "last_3h                                       1200\n",
       "last_4h                                       1200\n",
       "last_5h                                       1200\n",
       "last_6h                                       1200\n",
       "last_7h                                       1584\n",
       "last_8h                                       1584\n",
       "last_9h                                       1584\n",
       "last_10h                                      1584\n",
       "last_11h                                      1584\n",
       "last_12h                                      1584\n",
       "last_13h                                      1584\n",
       "last_14h                                      1584\n",
       "last_15h                                      1584\n",
       "last_16h                                      1584\n",
       "last_17h                                      1584\n",
       "last_18h                                      1584\n",
       "last_19h                                      1584\n",
       "last_20h                                      1584\n",
       "last_21h                                      1584\n",
       "last_22h                                      1584\n",
       "last_23h                                      1584\n",
       "last_24h                                      1584\n",
       "max_daily_budget                              1584\n",
       "dtype: object"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.max(axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "3a6497d5",
   "metadata": {},
   "outputs": [],
   "source": [
    "df['max_bdt']=df.iloc[:,2:26].max(axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "4f6b9e73",
   "metadata": {},
   "outputs": [],
   "source": [
    "df['df_bdt']='{}_{}'.format(df['max_bdt'],df['last_0h'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "4a9b8fad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ad_app_pkg_name</th>\n",
       "      <th>diff_budget</th>\n",
       "      <th>last_0h</th>\n",
       "      <th>last_1h</th>\n",
       "      <th>last_2h</th>\n",
       "      <th>last_3h</th>\n",
       "      <th>last_4h</th>\n",
       "      <th>last_5h</th>\n",
       "      <th>last_6h</th>\n",
       "      <th>last_7h</th>\n",
       "      <th>...</th>\n",
       "      <th>last_18h</th>\n",
       "      <th>last_19h</th>\n",
       "      <th>last_20h</th>\n",
       "      <th>last_21h</th>\n",
       "      <th>last_22h</th>\n",
       "      <th>last_23h</th>\n",
       "      <th>last_24h</th>\n",
       "      <th>max_daily_budget</th>\n",
       "      <th>max_bdt</th>\n",
       "      <th>df_bdt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>world.social.group.video.share</td>\n",
       "      <td>1200</td>\n",
       "      <td>0</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>...</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>1200</td>\n",
       "      <td>0    1200\\n1    1584\\n2     464\\n3    1000\\n4 ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ru.yandex.yandexmaps</td>\n",
       "      <td>494</td>\n",
       "      <td>1090</td>\n",
       "      <td>1090</td>\n",
       "      <td>1090</td>\n",
       "      <td>1090</td>\n",
       "      <td>1090</td>\n",
       "      <td>1090</td>\n",
       "      <td>1090</td>\n",
       "      <td>1584</td>\n",
       "      <td>...</td>\n",
       "      <td>1584</td>\n",
       "      <td>1584</td>\n",
       "      <td>1584</td>\n",
       "      <td>1584</td>\n",
       "      <td>1584</td>\n",
       "      <td>1584</td>\n",
       "      <td>1584</td>\n",
       "      <td>1584</td>\n",
       "      <td>1584</td>\n",
       "      <td>0    1200\\n1    1584\\n2     464\\n3    1000\\n4 ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ru.hh.android</td>\n",
       "      <td>464</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>464</td>\n",
       "      <td>464</td>\n",
       "      <td>...</td>\n",
       "      <td>464</td>\n",
       "      <td>464</td>\n",
       "      <td>464</td>\n",
       "      <td>464</td>\n",
       "      <td>464</td>\n",
       "      <td>464</td>\n",
       "      <td>464</td>\n",
       "      <td>464</td>\n",
       "      <td>464</td>\n",
       "      <td>0    1200\\n1    1584\\n2     464\\n3    1000\\n4 ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>com.plarium.raidlegends</td>\n",
       "      <td>450</td>\n",
       "      <td>550</td>\n",
       "      <td>550</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>...</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>0    1200\\n1    1584\\n2     464\\n3    1000\\n4 ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>com.WeWorld.WeCard</td>\n",
       "      <td>280</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>280</td>\n",
       "      <td>...</td>\n",
       "      <td>280</td>\n",
       "      <td>280</td>\n",
       "      <td>280</td>\n",
       "      <td>280</td>\n",
       "      <td>280</td>\n",
       "      <td>280</td>\n",
       "      <td>280</td>\n",
       "      <td>280</td>\n",
       "      <td>280</td>\n",
       "      <td>0    1200\\n1    1584\\n2     464\\n3    1000\\n4 ...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 30 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  ad_app_pkg_name  diff_budget  last_0h  last_1h  last_2h  \\\n",
       "0  world.social.group.video.share         1200        0     1200     1200   \n",
       "1            ru.yandex.yandexmaps          494     1090     1090     1090   \n",
       "2                   ru.hh.android          464        0        0        0   \n",
       "3         com.plarium.raidlegends          450      550      550     1000   \n",
       "4              com.WeWorld.WeCard          280        0        0        0   \n",
       "\n",
       "   last_3h  last_4h  last_5h  last_6h  last_7h  ...  last_18h  last_19h  \\\n",
       "0     1200     1200     1200     1200     1200  ...      1200      1200   \n",
       "1     1090     1090     1090     1090     1584  ...      1584      1584   \n",
       "2        0        0        0      464      464  ...       464       464   \n",
       "3     1000     1000     1000     1000     1000  ...      1000      1000   \n",
       "4        0        0        0        0      280  ...       280       280   \n",
       "\n",
       "   last_20h  last_21h  last_22h  last_23h  last_24h  max_daily_budget  \\\n",
       "0      1200      1200      1200      1200      1200              1200   \n",
       "1      1584      1584      1584      1584      1584              1584   \n",
       "2       464       464       464       464       464               464   \n",
       "3      1000      1000      1000      1000      1000              1000   \n",
       "4       280       280       280       280       280               280   \n",
       "\n",
       "   max_bdt                                             df_bdt  \n",
       "0     1200  0    1200\\n1    1584\\n2     464\\n3    1000\\n4 ...  \n",
       "1     1584  0    1200\\n1    1584\\n2     464\\n3    1000\\n4 ...  \n",
       "2      464  0    1200\\n1    1584\\n2     464\\n3    1000\\n4 ...  \n",
       "3     1000  0    1200\\n1    1584\\n2     464\\n3    1000\\n4 ...  \n",
       "4      280  0    1200\\n1    1584\\n2     464\\n3    1000\\n4 ...  \n",
       "\n",
       "[5 rows x 30 columns]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "d0f1077e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   Column1  Column2  Column3 New\n",
      "0        1        7        3   1\n",
      "1        2        4        8   2\n",
      "2        3        2       10    \n",
      "3        4        9       30   4\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "details = {\n",
    "    'Column1': [1, 2, 3, 4],\n",
    "    'Column2': [7, 4, 2, 9],\n",
    "    'Column3': [3, 8, 10, 30],\n",
    "}\n",
    " \n",
    "# creating a Dataframe object\n",
    "df2 = pd.DataFrame(details)\n",
    " \n",
    "# apply function\n",
    "df2['New'] = df2.apply(lambda x: x['Column1'] if x['Column1'] <=\n",
    "                     x['Column2'] and x['Column1']\n",
    "                     <= x['Column3'] else '', axis=1)\n",
    " \n",
    "# printing the dataframe\n",
    "print(df2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "10a4f85c",
   "metadata": {},
   "outputs": [],
   "source": [
    "account_ids = [u'pub-8441583395177875', u'pub-8908317842209223', u'pub-8078639535414849', u'pub-4974149037120311']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "0954e8eb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['pub-8441583395177875',\n",
       " 'pub-8908317842209223',\n",
       " 'pub-8078639535414849',\n",
       " 'pub-4974149037120311']"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "account_ids"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "51143c22",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "python",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
